﻿#include "BStree.h"

void TestKBS()
{
	int a[] = { 8, 3, 1, 12, 1, 6, 9, 7, 14, 13 };
	KBS::BSTree<int> t;

	for (auto e : a)
	{
		t.Insert(e);
	}
	KBS::BSTree<int> s;
	s.copy(t);
	t.InOrder();
	s.InOrder();
	//t.Insert(16);
	//t.InOrder();

	//t.Insert(3);
	//t.InOrder();

	////// 左右都不为空
	//t.Erase(8);
	//t.InOrder();

	//t.Erase(3);
	//t.InOrder();

	////// 右为空
	//t.Erase(14);
	//t.InOrder();

	////// 左为空
	//t.Erase(6);
	//t.InOrder();

	/*for (auto e : a)
	{
		t.Erase(e);
		t.InOrder();
	}*/
}



void TestKVBS()
{
	KVBS::BSTree<string, string> dict;
	dict.Insert("go", "去");
	dict.Insert("erase", "删除");
	dict.Insert("left", "左边");
	dict.Insert("find","找到");
	dict.Insert("string","字符串");
	dict.InOrder();
	string str;
	/*while (cin >> str)
	{
		auto ret = dict.Find(str);
		if (ret)
		{
			cout << str << ":" << ret->_value << endl;
		}
		else
		{
			cout << "单词拼写错误" << endl;
		}
	}*/

	dict.Erase("go");
	dict.InOrder();
	cout << endl;
	dict.Erase("erase");
	dict.InOrder();
	cout << endl;

	dict.Erase("left");
	dict.InOrder();
	cout << endl;

	dict.Erase("find");
	dict.InOrder();
	cout << endl;
	dict.Erase("string");
	dict.InOrder();


	string strs[] = { "葡萄","葡萄","葡萄","梨","苹果","苹果","苹果","香蕉","西瓜" };
	// 统计水果出现的次
	KVBS::BSTree<string, int> count;
	for (auto str : strs)
	{
		auto ret = count.Find(str);
		if (ret == NULL)
		{
			count.Insert(str, 1);
		}
		else
		{
			ret->_value++;
		}
	}
	count.InOrder();
		
}


int main()
{
	//TestKBS();
	TestKVBS();
	return 0;
}